/**
 * SqlMapOverviewPage.java : [com.ibader.eclipse.editors.sqlmap] Created on 2009. 5. 29.
 *
 * Copyright (c) 2009 Raccoon Project Team.
 * Seoul, Korea
 * All rights reserved.
 *
 */
package com.ibader.eclipse.editors.sqlmap;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.widgets.Section;

import com.ibader.eclipse.Activator;
import com.ibader.eclipse.editors.pages.IBaderEditorPage;

/**
 * @author KimJungSu
 * @version
 */
public class SqlMapOverviewPage extends IBaderEditorPage {

	private Section ginfoSection = null;
	private Section infoSection = null;

	private Text nameText = null;
	private Text nsText = null;
	private Text verText = null;
	private Text dtdText = null;
	private Text descText = null;

	public SqlMapOverviewPage(FormEditor editor, String id, String title) {
		super(editor, id, title);
		// TODO Auto-generated constructor stub
		Activator.log("+++SqlMapOverviewPage::Contructor");
		Activator.log("---SqlMapOverviewPage::Contructor");
	}

	@Override
	public boolean canLeaveThePage() {
		// TODO Auto-generated method stub
		return super.canLeaveThePage();
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		super.dispose();
	}

	@Override
	public void doSave(IProgressMonitor monitor) {
		// TODO Auto-generated method stub
		super.doSave(monitor);
	}

	@Override
	public void doSaveAs() {
		// TODO Auto-generated method stub
		super.doSaveAs();
	}

	@Override
	public void init(IEditorSite site, IEditorInput input) {
		// TODO Auto-generated method stub
		Activator.log("+++SqlMapOverviewPage::init");
		super.init(site, input);
		Activator.log("---SqlMapOverviewPage::init");
	}

	@Override
	public boolean isActive() {
		// TODO Auto-generated method stub
		return super.isActive();
	}

	@Override
	public boolean isDirty() {
		// TODO Auto-generated method stub
		return super.isDirty();
	}

	@Override
	public boolean isEditor() {
		// TODO Auto-generated method stub
		return super.isEditor();
	}

	@Override
	public boolean isSaveAsAllowed() {
		// TODO Auto-generated method stub
		return super.isSaveAsAllowed();
	}

	@Override
	public void setActive(boolean active) {
		// TODO Auto-generated method stub
		super.setActive(active);
	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub
		super.setFocus();
	}

	@Override
	public void setIndex(int index) {
		// TODO Auto-generated method stub
		super.setIndex(index);
	}

	@Override
	protected void createFormContent(IManagedForm managedForm) {
		// TODO Auto-generated method stub
		Activator.log("+++SqlMapOverviewPage::createFormContent");
		super.createFormContent(managedForm);

		// set form properties
		form.setExpandHorizontal(true);
		form.setExpandVertical(true);
		form.setText("Overview");
		form.getBody().setLayout(new FillLayout());

		Composite composite = toolkit.createComposite(form.getBody());
		toolkit.paintBordersFor(composite);
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		layout.makeColumnsEqualWidth = true;
		composite.setLayout(layout);
		//composite.setLayoutData(new GridData(GridData.FILL));

		// create General information content
		createGeneralInformationContent(composite);

		// create information content
		createInformationContent(composite);

		// initialize contents
		initContents();

		// add evnet listener for contents
		addContentEventListener();

		Activator.log("---SqlMapOverviewPage::createFormContent");
	}

	protected void addContentEventListener() {
		// TODO Auto-generated method stub
		Activator.log("+++SqlMapOverviewPage::addContentEventListener");

		Activator.log("---SqlMapOverviewPage::addContentEventListener");
	}

	protected void initContents() {
		// TODO Auto-generated method stub
		Activator.log("+++SqlMapOverviewPage::initContents");
		Activator.log("---SqlMapOverviewPage::initContents");
	}

	private void createInformationContent(Composite parent) {
		// TODO Auto-generated method stub
		Activator.log("+++SqlMapOverviewPage::createInformationContent");

		// create section for information
		infoSection = toolkit.createSection(parent,
				Section.DESCRIPTION | Section.TITLE_BAR | Section.EXPANDED);
		infoSection.marginWidth = 10;
		infoSection.setText("Information");
		infoSection.setDescription("Information's description");

		GridData gd = new GridData(GridData.FILL);
		infoSection.setLayoutData(gd);
		infoSection.setLayout(new FillLayout());

		// create controls for composite
		Composite composite = toolkit.createComposite(infoSection);
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		composite.setLayout(layout);

		// set client for information section
		infoSection.setClient(composite);


		Activator.log("---SqlMapOverviewPage::createInformationContent");
	}

	private void createGeneralInformationContent(Composite parent) {
		// TODO Auto-generated method stub
		Activator.log("+++SqlMapOverviewPage::createGeneralInformationContent");

		// create section for general information
		ginfoSection = toolkit.createSection(parent,
			Section.DESCRIPTION | Section.TITLE_BAR | Section.EXPANDED);
		ginfoSection.marginWidth = 10;
		ginfoSection.setText("General Information");
		ginfoSection.setDescription("General Information's description");

		GridData gd = new GridData(GridData.FILL);
		ginfoSection.setLayoutData(gd);
		ginfoSection.setLayout(new FillLayout());

		// create controls for composite
		Composite composite = toolkit.createComposite(ginfoSection);
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
//		layout.makeColumnsEqualWidth = false;
		composite.setLayout(layout);

		// set client for information
		ginfoSection.setClient(composite);

		// create control and set data
		gd = new GridData(GridData.BEGINNING);

		final Label nameLabel = new Label(composite, SWT.NONE);
		nameLabel.setText("Name:");
		nameLabel.setLayoutData(gd);

		gd = new GridData(GridData.FILL_HORIZONTAL);
		nameText = new Text(composite, SWT.BORDER);
		nameText.setLayoutData(gd);

		gd = new GridData(GridData.BEGINNING);
		final Label nsLabel = new Label(composite, SWT.NONE);
		nsLabel.setText("NameSpace:");
		nsLabel.setLayoutData(gd);

		gd = new GridData(GridData.FILL_HORIZONTAL);
		nsText = new Text(composite, SWT.BORDER);
		nsText.setLayoutData(gd);

		gd = new GridData(GridData.BEGINNING);
		final Label verLabel = new Label(composite, SWT.NONE);
		verLabel.setText("Version:");
		verLabel.setLayoutData(gd);

		gd = new GridData(GridData.FILL_HORIZONTAL);
		verText = new Text(composite, SWT.BORDER);
		verText.setLayoutData(gd);

		gd = new GridData(GridData.BEGINNING);
		final Label dtdLabel = new Label(composite, SWT.NONE);
		dtdLabel.setText("DTD:");
		dtdLabel.setLayoutData(gd);

		gd = new GridData(GridData.FILL_HORIZONTAL);
		dtdText = new Text(composite, SWT.BORDER);
		dtdText.setLayoutData(gd);

		gd = new GridData(GridData.BEGINNING);
		final Label descLabel = new Label(composite, SWT.NONE);
		descLabel.setText("Description:");
		descLabel.setLayoutData(gd);

		gd = new GridData(GridData.FILL_HORIZONTAL);
		descText = new Text(composite, SWT.BORDER);
		descText.setLayoutData(gd);

		Activator.log("---SqlMapOverviewPage::createGeneralInformationContent");
	}

	@Override
	public void propertyChange(PropertyChangeEvent event) {
		// TODO Auto-generated method stub
		editor.editorDirtyStateChanged();
	}

}
